;:ifpeek(776)<>228then:]x
;:poke56,128
;:sys36864
	;.opt oo
	*= $8000
	jmp init
chrget	=115
chrgot	=121
konf	=1
mem	=$a000
tmp	=2
tmp2	=tmp+2
statvec	=$308
basptr	=chrgot+1
inter	=$a7ae
strout	=$ab1e
sign	="]"
return	=$aad7
crs1	=204
crs2	=207
linehi	=$3a
getkey	=65508
data	=$a8f8
page	=$60
chrout	=$ffd2
axout	=$bdcd
spalte	=211
maxfil	=10
getx	=$b79e
illquan	=$b248
errorx	=$a437
komma	=$aefd
frmevl	=$ad9e
frestr	=$b6a3
stradr	=$22
toolong	=$a571
old	=$a7e7
syntax	=$af08
stattab	.byte "xfdoc"
statadr	.word exit,format,dir,open,close
bye	.byte "\x11good bye !"
	.byt 13,0
suretxt	.byte "are you sure ? (y/n) "
	.byt 0
lat	.byt 0
lat2	.byt 0
typ0	.byte "prg "
	.byt 0
typ1	.byte "seq "
	.byt 0
ta0	.byte "                "
	.word 0,0
	.byt 0
ta1	.byte "                "
	.word 0,0
	.byt 0
ta2	.byte "                "
	.word 0,0
	.byt 0
ta3	.byte "                "
	.word 0,0
	.byt 0
ta4	.byte "                "
	.word 0,0
	.byt 0
ta5	.byte "                "
	.word 0,0
	.byt 0
ta6	.byte "                "
	.word 0,0
	.byt 0
ta7	.byte "                "
	.word 0,0
	.byt 0
ta8	.byte "                "
	.word 0,0
	.byt 0
ta9	.byte "                "
	.word 0,0
	.byt 0
tabtab	.word ta0,ta1,ta2,ta3,ta4,ta5,ta6,ta7,ta8,ta9
init	lda #<newstat
	ldy #>newstat
	sta statvec
	sty statvec+1
	jsr dirinit
	jmp initzp
newstat	jsr chrget
	cmp #sign
	beq neu
	jsr chrgot
	jmp old
neu	jsr chrget
	ldy #statadr-stattab-1
such	cmp stattab,y
	beq found
	dey
	bpl such
	jmp syntax
found	tya
	asl
	tay
	lda statadr,y
	sta tmp
	lda statadr+1,y
	sta tmp+1
	jsr chrget
	jsr jump
	jmp inter
jump	jmp (tmp)
exit	lda #<old-3
	sta statvec
	lda #>old-3
	sta statvec+1
	lda #<bye
	ldy #>bye
	jmp strout
format	jsr sure
	jsr dirinit
	jsr ram
	lda #<mem
	ldy #>mem
	sta tmp
	sty tmp+1
	lda #0
	ldx #page
	tay
l1	sta (tmp),y
	iny
	bne l1
	inc tmp+1
	dex
	bne l1
	jmp rom
sure	ldx linehi
	inx
	beq direct
prg	rts
direct	lda #<suretxt
	ldy #>suretxt
	jsr strout
	lda #0
	sta crs1
gyn	jsr getkey
	cmp #"y"
	beq yes
	cmp #"j"
	beq yes
	cmp #"n"
	bne gyn
	pla
	pla
	jsr data
	lda basptr
	sec
	sbc #1
	sta basptr
	lda basptr+1
	sbc #0
	sta basptr+1
	lda #"n"
yes	jsr chrout
l2	lda crs2
	bne l2
	lda #1
	sta crs1
	jmp return
ram	lda konf
	sta rom+1
	lda #48
	sei
	sta konf
	rts
rom	lda #0
	sta konf
	cli
	rts
initzp	lda #55
	sta rom+1
	rts
dirinit	ldy #tabtab-ta0-1
	lda #0
l3	sta ta0,y
	dey
	cpy #255
	bne l3
	rts
ptrx	pha
	txa
	pha
	asl
	tax
	lda tabtab,x
	sta tmp
	lda tabtab+1,x
	sta tmp+1
	pla
	tax
	pla
	rts
dir	ldx #0
l4	jsr ptrx
	ldy #20
	lda (tmp),y
	sta lat
	and #4
	stx lat2
	beq closed
	inx
	lda #0
	jsr axout
	lda #3
	sta spalte
	ldy #0
l5	lda (tmp),y
	cmp #0
	beq l6
	jsr chrout
	iny
	cpy #16
	bcc l5
l6	lda #20
	sta spalte
	lda lat
	and #1
	beq prgfile
	lda #<typ1
	ldy #>typ1
	bne l12
prgfile	lda #<typ0
	ldy #>typ0
l12	jsr strout
	jsr return
closed	ldx lat2
	inx
	cpx #maxfil
	bcc l4
	rts
close	jsr filenr
	ldy #20
	lda (tmp),y
	and #%11111101
	sta (tmp),y
	rts
filenr	jsr getx
	dex
	bpl l7
ill	jmp illquan
l7	cpx #maxfil
	bcs ill
	jmp ptrx
open	jsr filenr
	ldy #20
	lda (tmp),y
	and #2
	beq l8
	ldx #2
	jmp errorx
l8	lda (tmp),y
	ora #%00000111
	sta (tmp),y
	jsr clrnam
	jsr komma
	jsr frmevl
	jsr frestr
	tay
	cmp #17
	bcc l10
	jmp toolong
l10	dey
	bmi l11
	lda (stradr),y
	sta (tmp),y
	clc
	bcc l10
l11	rts
clrnam	lda #0
	ldy #15
l9	sta (tmp),y
	dey
	bpl l9
	rts
